package com.example.mingyue.mq;

import com.example.mingyue.constant.MqConstant;
import com.example.mingyue.model.entity.Post;
import com.example.mingyue.service.PostService;
import com.example.mingyue.service.UserService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 监听mq消息,包含
 * 用户的cd队列
 * 帖子的cd队列
 */
@Component
public class Listener {

    @Autowired
    private UserService userService;

    /**
     * 监听添加的业务对ES进行数据同步
     * @param id
     */
    @RabbitListener(queues = MqConstant.MINGYUE_INSERT_QUEUE)
    public void listenerInsertQueue(Integer id){
        userService.insertUserES(id);
    }

    /**
     * 监听删除的业务对ES进行数据同步
     * @param id
     */
    @RabbitListener(queues = MqConstant.MINGYUE_DELETE_QUEUE)
    public void listenerDeleteQueue(Integer id){
        userService.deleteUserES(id);
    }


    @Autowired
    private PostService postService;
    /**
     * 监听新增帖子的队列
     * @param id
     */
    @RabbitListener(queues = MqConstant.MINGYUE_INSERTPOST_QUEUE)
    public void listenerInsertPostQueue(Integer id){
        postService.insertPostES(id);
    }

    /**
     * 监听删除帖子的队列
     * @param id
     */
    @RabbitListener(queues = MqConstant.MINGYUE_DELETEPOST_QUEUE)
    public void listenerDeletePostQueue(Integer id){
        postService.deletePostES(id);
    }

}
